// 定义 Car 类
class Car(val licensePlate: String, val brand: String, val color: String, val price: Double) {
  // 汽车的基本属性
  def displayInfo(): Unit = {
    println(s"License Plate: $licensePlate")
    println(s"Brand: $brand")
    println(s"Color: $color")
    println(s"Price: $$${price}")
  }

  // 驾驶方法
  def drive(): Unit = {
    println("The car is driving.")
  }

  // 停车方法
  def park(): Unit = {
    println("The car is parked.")
  }

  // 加油方法
  def refuel(): Unit = {
    println("The car is refueling.")
  }
}

// 定义 ElectricCar 类，继承自 Car 类
class ElectricCar(licensePlate: String, brand: String, color: String, price: Double,
                  val batteryCapacity: Double, val range: Double) 
  extends Car(licensePlate, brand, color, price) {

  // 充电方法
  def charge(): Unit = {
    println("The electric car is charging.")
  }

  // 重写 drive 方法，电动汽车需要检查电池续航
  override def drive(): Unit = {
    if (range > 0) {
      println(s"The electric car is driving. Remaining range: $range km.")
    } else {
      println("Cannot drive. The battery is empty.")
    }
  }

  // 重写 displayInfo 方法，展示电动汽车的特有属性
  override def displayInfo(): Unit = {
    super.displayInfo()
    println(s"Battery Capacity: $batteryCapacity kWh")
    println(s"Range: $range km")
  }
}

// 测试代码
object Main extends App {
  // 创建一辆普通的汽车
  val myCar = new Car("ABC123", "Toyota", "Red", 25000)
  println("Car Info:")
  myCar.displayInfo()
  myCar.drive()
  myCar.park()
  myCar.refuel()
  println()

  // 创建一辆电动汽车
  val myElectricCar = new ElectricCar("XYZ789", "Tesla", "Blue", 50000, 75, 400)
  println("Electric Car Info:")
  myElectricCar.displayInfo()
  myElectricCar.charge()
  myElectricCar.drive()
}
